/**
 * Created by yindu on 2018/12/17.
 */
var express = require('express');
var router = express.Router();
var db = require('../libs/mysql');

//统一返回格式
var res_Data;
router.use( function(req, res, next) {
    res_Data = {
        code: 0,
        message: ''
    }
    next();
});

router.get('/',function (req,res) {
    var id = req.query.id;
    db.query(`SELECT * FROM home WHERE id=${id}`,(err,data)=>{
        if(err){
            res.send('修改课程数据查询').end();
        }else {
            res.json(data[0]);
        }
    })
})
router.post('/',function (req,res) {
    var id = req.body.id;
    var data = req.body.addContent;
    var title = data.title,
        author = data.author,
        start_time = data.start_time,
        end_time = data.end_time;

    db.query(`UPDATE home SET title='${title}',author='${author}',start_time ='${start_time}',end_time = '${end_time}' WHERE id = ${id};`,(err)=>{
        if(err){
            res.send('修改课程').end();
        }else {
            res_Data.message = '修改成功';
            res.json(res_Data);
            return;
        }
    })
})

module.exports = router;